﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _3D_Demo
{
    public class PerspectiveCamera : Camera
    {
        private float _zNearPlaneDistance;

        public float ZNearPlaneDistance
        {
            get { return _zNearPlaneDistance; }
            set { _zNearPlaneDistance = value; }
        }
        private float _zFarPlaneDistance;

        public float ZFarPlaneDistance
        {
            get { return _zFarPlaneDistance; }
            set { _zFarPlaneDistance = value; }
        }
        private float _FielOfView;

        public float FielOfView
        {
            get { return _FielOfView; }
            set { _FielOfView = value; }
        }
        private float _AspectRatio;

        public float AspectRatio
        {
            get { return _AspectRatio; }
            set { _AspectRatio = value; }
        }
        public void InitCamera(
            Vector3 cameraPosition,
            Vector3 cameraTarget,
            Vector3 cameraUpVector,
            float nearPlaneDistance,
            float farPlaneDistance,
            float fieldOfView,
            float aspectRation)
        {
            CameraPosition = cameraPosition;
            CameraUpVector = cameraUpVector;
            CameraTarget = cameraTarget;
            ZNearPlaneDistance = nearPlaneDistance;
            ZFarPlaneDistance = farPlaneDistance;
            FielOfView = fieldOfView;
            AspectRatio = aspectRation;
            InternalUpdateMatrices();

        }

        private void InternalUpdateMatrices()
        {
            View = Matrix.CreateLookAt(
                CameraPosition, CameraTarget, CameraUpVector
                );
            Projection = Matrix.CreatePerspectiveFieldOfView(
               FielOfView,
               AspectRatio,
               ZNearPlaneDistance,
               ZFarPlaneDistance);
        }
        public override void Update(GameTime gameTime)
        {
            InternalUpdateMatrices();
            base.Update(gameTime);
        }
    }
}
